package com.supermarket.mapper;

import com.supermarket.entity.OperationLog;
import com.supermarket.vo.OperationLogVo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface OperationLogMapper {

    @Insert("INSERT INTO operation_log (user_id, operation, operation_type, ip_address, create_time) " +
            "VALUES (#{userId}, #{operation}, #{operationType}, #{ipAddress}, #{createTime})")
    void insert(OperationLog operationLog);

    @Select("SELECT ol.*, u.username FROM operation_log ol " +
            "LEFT JOIN user u ON ol.user_id = u.id " +
            "ORDER BY ol.create_time DESC")
    List<OperationLogVo> findAll();

    @Select("SELECT ol.*, u.username FROM operation_log ol " +
            "LEFT JOIN user u ON ol.user_id = u.id " +
            "WHERE ol.user_id = #{userId} " +
            "ORDER BY ol.create_time DESC")
    List<OperationLogVo> findByUserId(Long userId);
} 